﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;
using UI;


namespace BDCS.UI
{
    public partial class SystemManageWindow : Form
    {
        #region 成员字段
        private BDCS.BLL.T_BuildTyppes bllBuildType;
        private BDCS.BLL.T_SubBuildTyppes bllSubBuildType;
        private BDCS.BLL.T_BuildDesignDcriterionTypes bllBuildDesignDcriterionType;
        private BDCS.BLL.T_SubBuildAttributes bllSubBuildAttribute;
        private BDCS.BLL.T_BuildDesignDcriterionSubTypes bllBuildDesignDcriterionSubType;
        private BDCS.BLL.T_SubAttributes bllSubAttribute;
        private BDCS.Model.T_SubAttributes modelSubAttribute;
        private BDCS.BLL.T_BuildDesignDcriterionContents bllBuildDesignDcriterionContent;
        private BDCS.Model.T_BuildDesignDcriterionContents modelBuildDesignDcriterionContent;
        private BDCS.Model.T_SubBuildTyppes modelSubBuildType;
        private BDCS.Model.T_SubBuildAttributes modelSubBuildAttribute;
        private BDCS.Model.T_BuildDesignDcriterionTypes modelBuildDesignDcriterionType;
        private BDCS.Model.T_BuildDesignDcriterionSubTypes modelBuildDesignDcriterionSubType;
        private DataSet dataSet;
        private int sbtid;
        private int btid;
        private int dtid;
        private int dstid;
        private int sbaid;
        private int selectTag;
        private string selectText;
        private int selectIndex;
        private int selectIndexTwo;
        private int selectTagTwo;
        private string selectTextTwo;
        private bool isChange;
        #endregion
        #region 构造函数
        public SystemManageWindow()
        {
            InitializeComponent();
        }
        #endregion
        #region 成员事件
        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
            {
                if (trvBuildAttrbute.SelectedNode.Text == nd.Text)
                {
                    btid = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Tag);
                    // btName = trvBuildAttrbute.SelectedNode.Text.ToString();
                    Model.T_BuildTyppes MBT = new Model.T_BuildTyppes();
                    bllBuildType = new BLL.T_BuildTyppes();
                    MBT = bllBuildType.GetModel(btid);
                    AlterBuildTypescs ABT = new AlterBuildTypescs(MBT);
                    ABT.Show();
                }
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    if (trvBuildAttrbute.SelectedNode.Text == treeNode.Text)
                    {
                        sbtid = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Tag);
                        //   btid = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Parent.Tag);
                        modelSubBuildType = new Model.T_SubBuildTyppes();
                        bllSubBuildType = new BLL.T_SubBuildTyppes();
                        modelSubBuildType = bllSubBuildType.GetModel(sbtid);
                        AlterSubBuildTypes ASBT = new AlterSubBuildTypes(modelSubBuildType);
                        ASBT.Show();
                    }
                    foreach (TreeNode treeNodeNew in treeNode.Nodes)
                    {
                        if (trvBuildAttrbute.SelectedNode.Text == treeNodeNew.Text)
                        {
                            sbaid = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Tag);
                            modelSubBuildAttribute = new Model.T_SubBuildAttributes();
                            bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
                            modelSubBuildAttribute = bllSubBuildAttribute.GetModel(sbaid);
                            AlterSubBuildAttributes ASBA = new AlterSubBuildAttributes(modelSubBuildAttribute);
                            ASBA.Show();
                        }
                    }
                }
            }

        }
        private void 上一条ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 新增建筑子类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSubBuildTypes ASBT = new AddSubBuildTypes();
            ASBT.Show();
        }

        private void 新增建筑子类属性ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSubBuildAttributes ASBA = new AddSubBuildAttributes();
            ASBA.Show();
        }

        private void 新增建筑子类属性值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSubAttributes ASA = new AddSubAttributes();
            ASA.Show();
        }

        private void 新增规范大类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddBuildDesignDcriterionTypes ABDD = new AddBuildDesignDcriterionTypes();
            ABDD.Show();
        }
        private void 新增规范子类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddBuildDesignDcriterionSubTypes ABDDST = new AddBuildDesignDcriterionSubTypes();
            ABDDST.Show();
        }
        private void 新增规范子类值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddBuildDesignDcriterionContents ABDDC = new AddBuildDesignDcriterionContents();
            ABDDC.Show();
        }
        private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSubBuildDcriterionContents ASBDC = new AddSubBuildDcriterionContents();
            ASBDC.Show();
        }
        private void 退出EToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form F = this.FindForm();
            F.Close();
        }
        private void SystemManageWindow_Load(object sender, EventArgs e)
        {
            selectIndex = 0;
            selectIndexTwo = 0;
            TreeNode node = new TreeNode();
            node.Text = "建筑参数数据字典";
            trvBuildAttrbute.Nodes.Add(node);
            dataSet = new DataSet();
            bllBuildType = new BLL.T_BuildTyppes();
            dataSet = bllBuildType.GetAllList();
            BindNode(node, dataSet, "BTName", "BTID");
            TreeNode nodeTwo = new TreeNode();
            nodeTwo.Text = "设计规范数据字典";
            trvDesignDcriterion.Nodes.Add(nodeTwo);
            bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
            dataSet.Clear();
            dataSet = bllBuildDesignDcriterionType.GetAllList();
            BindNode(nodeTwo, dataSet, "DTName", "DTID");
            this.toolStripStatusLabel1.Text = DateTime.Now.ToLongDateString();
            this.toolStripStatusLabel2.Text = DateTime.Now.ToLongTimeString();
            this.toolStripStatusLabel3.Text = "                                                        操作人员:Admin";
            this.toolStripStatusLabel4.Text = "                                                                                                                                                                                                成都某某设计院";
        }
        private void trvDesignDcriterion_DoubleClick(object sender, EventArgs e)
        {
            if (selectIndexTwo == 0 || BDCS.Common.TreeViewState.IsChangedDcriterion == true)
            {
                trvDesignDcriterion.Nodes[0].Nodes.Clear();
                dataSet = new DataSet();
                bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
                dataSet = bllBuildDesignDcriterionType.GetAllList();
                BindNode(trvDesignDcriterion.Nodes[0], dataSet, "DTName", "DTID");
                bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
                foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
                {
                    trvDesignDcriterion.SelectedNode = nd;
                    trvDesignDcriterion.SelectedNode.Nodes.Clear();
                    dtid = Convert.ToInt32(this.trvDesignDcriterion.SelectedNode.Tag);
                    dataSet.Clear();
                    dataSet = bllBuildDesignDcriterionSubType.GetList("DTID=" + "'" + dtid + "'");
                    BindNode(nd, dataSet, "DSTName", "DSTID");
                }
                selectIndexTwo++;
                BDCS.Common.TreeViewState.IsChangedDcriterion = false;
            }
            selectTagTwo = Convert.ToInt32(trvDesignDcriterion.SelectedNode.Tag);
            selectTextTwo = trvDesignDcriterion.SelectedNode.Text;
            SelectChangeDcriterion(selectTagTwo, selectTextTwo);
            foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
            {
                if (nd.Text == selectTextTwo)
                {
                    dgvContent.Columns.Clear();
                }
            }
        }
        private void trvBuildAttrbute_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (selectIndex == 0 || BDCS.Common.TreeViewState.IsChangedAttribute == true)
            {
                trvBuildAttrbute.Nodes[0].Nodes.Clear();
                dataSet = new DataSet();
                bllBuildType = new BLL.T_BuildTyppes();
                dataSet = bllBuildType.GetAllList();
                BindNode(trvBuildAttrbute.Nodes[0], dataSet, "BTName", "BTID");
                bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
                foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
                {
                    trvBuildAttrbute.SelectedNode = nd;
                    trvBuildAttrbute.SelectedNode.Nodes.Clear();
                    dataSet = new DataSet();
                    btid = Convert.ToInt32(nd.Tag);
                    dataSet.Clear();
                    bllSubBuildType = new BLL.T_SubBuildTyppes();
                    dataSet = bllSubBuildType.GetList("BTID=" + "'" + btid + "'");
                    BindNode(nd, dataSet, "SBTName", "SBTID");
                    foreach (TreeNode treeNode in nd.Nodes)
                    {
                        trvBuildAttrbute.SelectedNode = treeNode;
                        dataSet = new DataSet();
                        dataSet.Clear();
                        trvBuildAttrbute.SelectedNode.Nodes.Clear();
                        sbtid = Convert.ToInt32(treeNode.Tag);
                        dataSet = bllSubBuildAttribute.GetList("SBTID=" + "'" + sbtid + "'");
                        BindNode(treeNode, dataSet, "SBAContent", "SBAID");
                    }
                }
                selectIndex++;
                BDCS.Common.TreeViewState.IsChangedAttribute = false;
            }
            selectText = trvBuildAttrbute.SelectedNode.Text;
            selectTag = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Tag);
            SelectChangeAttribute(selectTag, selectText);
            foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
            {
                if (nd.Text != selectText)
                {
                    foreach (TreeNode treeNode in nd.Nodes)
                    {
                        if (treeNode.Text == selectText)
                        {
                            dgvContent.Columns.Clear();
                        }
                    }
                }
                else
                {
                    dgvContent.Columns.Clear();
                }
            }
        }
        private void dgvContent_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            foreach (DataGridViewColumn dgc in dgvContent.Columns)
            {
                if (dgc.HeaderText == "建筑大类")
                {
                    UpdateAttrtibute();
                }
                if (dgc.HeaderText == "规范大类")
                {
                    UpdateDesignDcriterion();
                }
            }

        }
        private void 修改ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
            {
                if (nd.Text == trvDesignDcriterion.SelectedNode.Text)
                {
                    dtid = Convert.ToInt32(trvDesignDcriterion.SelectedNode.Tag);
                    bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
                    modelBuildDesignDcriterionType = new Model.T_BuildDesignDcriterionTypes();
                    modelBuildDesignDcriterionType = bllBuildDesignDcriterionType.GetModel(dtid);
                    AlterBuildDesignDcriterionTypes ABDDT = new AlterBuildDesignDcriterionTypes(modelBuildDesignDcriterionType);
                    ABDDT.Show();
                }
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    if (treeNode.Text == trvDesignDcriterion.SelectedNode.Text)
                    {
                        dstid = Convert.ToInt32(trvDesignDcriterion.SelectedNode.Tag);
                        bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
                        modelBuildDesignDcriterionSubType = new Model.T_BuildDesignDcriterionSubTypes();
                        modelBuildDesignDcriterionSubType = bllBuildDesignDcriterionSubType.GetModel(dstid);
                        AlterBuildDesignDcriterionSubTypes ABDDST = new AlterBuildDesignDcriterionSubTypes(modelBuildDesignDcriterionSubType);
                        ABDDST.Show();
                    }
                }
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
            {
                if (trvBuildAttrbute.SelectedNode.Text == nd.Text)
                {
                    btid = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Tag);
                    try
                    {
                        bllBuildType = new BLL.T_BuildTyppes();
                        bllBuildType.Delete(btid);
                        foreach (TreeNode treeNodeOne in nd.Nodes)
                        {
                            sbaid = Convert.ToInt32(treeNodeOne.Tag);
                            try
                            {
                                bllSubBuildType = new BLL.T_SubBuildTyppes();
                                bllSubBuildType.Delete(sbtid);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString());
                            }
                            foreach (TreeNode tr in treeNodeOne.Nodes)
                            {
                                sbaid = Convert.ToInt32(tr.Tag);
                                try
                                {
                                    bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
                                    bllSubBuildAttribute.Delete(sbaid);
                                    List<Model.T_SubAttributes> listSubAttribute = new List<Model.T_SubAttributes>();
                                    bllSubAttribute = new BLL.T_SubAttributes();
                                    listSubAttribute = bllSubAttribute.GetModelList("SBAID=" + "'" + sbaid + "'");
                                    foreach (Model.T_SubAttributes sa in listSubAttribute)
                                    {
                                        try
                                        {
                                            bllSubAttribute.Delete(sa.SAID);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message.ToString());
                                        }
                                    }

                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message.ToString());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                    }
                    trvBuildAttrbute.SelectedNode.Remove();
                    dgvContent.Columns.Clear();
                    MessageBox.Show("大类、子类、子类属性、子类属性值删除成功！");
                }
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    if (treeNode.Text == trvBuildAttrbute.SelectedNode.Text)
                    {
                        sbtid = Convert.ToInt32(trvBuildAttrbute.SelectedNode.Tag);
                        modelSubBuildType = new Model.T_SubBuildTyppes();
                        bllSubBuildType = new BLL.T_SubBuildTyppes();
                        try
                        {
                            bllSubBuildType.Delete(sbtid);

                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }
                        foreach (TreeNode treeNodeTwo in treeNode.Nodes)
                        {
                            sbaid = Convert.ToInt32(treeNodeTwo.Tag);
                            try
                            {
                                bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
                                bllSubBuildAttribute.Delete(sbaid);
                                List<Model.T_SubAttributes> listSubAttribute = new List<Model.T_SubAttributes>();
                                bllSubAttribute = new BLL.T_SubAttributes();
                                listSubAttribute = bllSubAttribute.GetModelList("SBAID=" + "'" + sbaid + "'");
                                foreach (Model.T_SubAttributes sa in listSubAttribute)
                                {
                                    try
                                    {
                                        bllSubAttribute.Delete(sa.SAID);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.Message.ToString());
                                    }
                                }

                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString());
                            }
                        }
                        trvBuildAttrbute.SelectedNode.Remove();
                        dgvContent.Columns.Clear();
                        MessageBox.Show("子类，子类属性，属性值删除成功！");
                    }
                    foreach (TreeNode treeNodeThree in treeNode.Nodes)
                    {
                        if (treeNodeThree.Text == trvBuildAttrbute.SelectedNode.Text)
                        {

                            sbaid = Convert.ToInt32(treeNodeThree.Tag);
                            try
                            {
                                bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
                                bllSubBuildAttribute.Delete(sbaid);
                                List<Model.T_SubAttributes> listSubAttribute = new List<Model.T_SubAttributes>();
                                bllSubAttribute = new BLL.T_SubAttributes();
                                listSubAttribute = bllSubAttribute.GetModelList("SBAID=" + "'" + sbaid + "'");
                                if (listSubAttribute.Count > 0)
                                {
                                    foreach (Model.T_SubAttributes sa in listSubAttribute)
                                    {
                                        try
                                        {
                                            bllSubAttribute.Delete(sa.SAID);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message.ToString());
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString());
                            }
                            trvBuildAttrbute.SelectedNode.Remove();
                            dgvContent.Columns.Clear();
                            MessageBox.Show("子类属性，属性值删除成功！");
                        }
                    }
                }
            }
        }

        private void 新增建筑大类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddBuildTypes AT = new AddBuildTypes();
            AT.Show();
        }

        private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
            {
                if (trvDesignDcriterion.SelectedNode.Text == nd.Text)
                {
                    dtid = Convert.ToInt32(trvDesignDcriterion.SelectedNode.Tag);
                    try
                    {
                        bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
                        bllBuildDesignDcriterionType.Delete(dtid);
                        foreach (TreeNode treeNodeOne in nd.Nodes)
                        {
                            dstid = Convert.ToInt32(treeNodeOne.Tag);
                            try
                            {
                                bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
                                bllBuildDesignDcriterionSubType.Delete(dstid);
                                List<Model.T_BuildDesignDcriterionContents> lisDcid = new List<Model.T_BuildDesignDcriterionContents>();
                                bllBuildDesignDcriterionContent = new BLL.T_BuildDesignDcriterionContents();
                                lisDcid = bllBuildDesignDcriterionContent.GetModelList("DSTID=" + "'" + dstid + "'");
                                foreach (Model.T_BuildDesignDcriterionContents mc in lisDcid)
                                {
                                    try
                                    {
                                        bllBuildDesignDcriterionContent.Delete(mc.DCID);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.Message.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString());
                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                    }
                    trvDesignDcriterion.SelectedNode.Remove();
                    dgvContent.Columns.Clear();
                    MessageBox.Show("规范大类、规范子类、子类属性值删除成功！");
                }
                foreach (TreeNode treeNodeTwo in nd.Nodes)
                {
                    if (trvDesignDcriterion.SelectedNode.Text == treeNodeTwo.Text)
                    {

                        dstid = Convert.ToInt32(treeNodeTwo.Tag);
                        try
                        {
                            bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
                            bllBuildDesignDcriterionSubType.Delete(dstid);
                            List<Model.T_BuildDesignDcriterionContents> lisDcid = new List<Model.T_BuildDesignDcriterionContents>();
                            bllBuildDesignDcriterionContent = new BLL.T_BuildDesignDcriterionContents();
                            lisDcid = bllBuildDesignDcriterionContent.GetModelList("DSTID=" + "'" + dstid + "'");
                            foreach (Model.T_BuildDesignDcriterionContents mc in lisDcid)
                            {
                                try
                                {
                                    bllBuildDesignDcriterionContent.Delete(mc.DCID);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message.ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }
                        trvDesignDcriterion.SelectedNode.Remove();
                        dgvContent.Columns.Clear();
                        MessageBox.Show("规范子类、子类属性值删除成功！");
                    }
                }
            }
        }
        private void 新增AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (trvBuildAttrbute.Nodes[0].IsSelected == true)
            {
                AddBuildTypes addBuildType = new AddBuildTypes();
                addBuildType.Show();
            }
            foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
            {
                if (nd.IsSelected == true)
                {
                    BDCS.UI.AddSubBuildTypes addSubBuildType = new AddSubBuildTypes();
                    addSubBuildType.Show();
                }
                foreach (TreeNode treeNodeFour in nd.Nodes)
                {
                    if (treeNodeFour.IsSelected == true)
                    {
                        AddSubBuildAttributes addSubBuildAttribute = new AddSubBuildAttributes();
                        addSubBuildAttribute.ShowDialog();
                        DialogResult dr = MessageBox.Show("是否添加属性值？", "添加属性值提示框", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            UI.AddSubAttributes addSubAttribute = new AddSubAttributes();
                            addSubAttribute.Show();
                        }
                    }
                }
            }
        }

        private void 新增同级SToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
            {
                if (nd.IsSelected == true)
                {
                    AddBuildTypes ABT = new AddBuildTypes();
                    ABT.Show();
                }
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    if (treeNode.IsSelected == true)
                    {
                        AddSubBuildTypes ASBT = new AddSubBuildTypes();
                        ASBT.Show();
                    }
                    foreach (TreeNode treeNodeOne in treeNode.Nodes)
                    {
                        if (treeNodeOne.IsSelected == true)
                        {
                            AddSubBuildAttributes addSubBuildAttribute = new AddSubBuildAttributes();
                            addSubBuildAttribute.ShowDialog();
                            DialogResult dr = MessageBox.Show("是否添加属性值？", "添加属性值提示框", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.Yes)
                            {
                                UI.AddSubAttributes addSubAttribute = new AddSubAttributes();
                                addSubAttribute.Show();
                            }
                        }
                    }

                }
            }
        }

        private void 新增AToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (trvDesignDcriterion.Nodes[0].IsSelected == true)
            {
                AddBuildDesignDcriterionTypes ABDDT = new AddBuildDesignDcriterionTypes();
                ABDDT.Show();
            }
            foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
            {
                if (nd.IsSelected == true)
                {
                    AddBuildDesignDcriterionSubTypes ABDDST = new AddBuildDesignDcriterionSubTypes();
                    ABDDST.ShowDialog();
                    DialogResult dr = MessageBox.Show("是否添加g规范值？", "添加规范值提示框", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        AddBuildDesignDcriterionContents ABDDC = new AddBuildDesignDcriterionContents();
                        ABDDC.Show();
                    }
                }
            }
        }

        private void 新增同级SToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
            {
                AddBuildDesignDcriterionTypes ABDDT = new AddBuildDesignDcriterionTypes();
                ABDDT.Show();
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    if (treeNode.IsSelected == true)
                    {
                        AddBuildDesignDcriterionSubTypes ABDDST = new AddBuildDesignDcriterionSubTypes();
                        ABDDST.ShowDialog();
                        DialogResult dr = MessageBox.Show("是否添加g规范值？", "添加规范值提示框", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            AddBuildDesignDcriterionContents ABDDC = new AddBuildDesignDcriterionContents();
                            ABDDC.Show();
                        }
                    }
                }
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            AddBuildTypes ABT = new AddBuildTypes();
            ABT.Show();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            AddSubBuildTypes ASBT = new AddSubBuildTypes();
            ASBT.Show();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            AddSubBuildAttributes ASBA = new AddSubBuildAttributes();
            ASBA.Show();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            AddSubAttributes ASA = new AddSubAttributes();
            ASA.Show();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            AddBuildDesignDcriterionTypes ABDDT = new AddBuildDesignDcriterionTypes();
            ABDDT.Show();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            AddBuildDesignDcriterionSubTypes ABDDST = new AddBuildDesignDcriterionSubTypes();
            ABDDST.Show();
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            AddBuildDesignDcriterionContents ABDDC = new AddBuildDesignDcriterionContents();
            ABDDC.Show();
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            AddSubBuildDcriterionContents ASBDC = new AddSubBuildDcriterionContents();
            ASBDC.Show();
        }
        #endregion
        #region 方法成员
        private void BindNode(TreeNode nd, DataSet ds, string name, string id)
        {

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                TreeNode node = new TreeNode();
                node.Text = ds.Tables[0].Rows[i][name].ToString();
                node.Tag = ds.Tables[0].Rows[i][id].ToString();
                nd.Nodes.Add(node);
                //BindNode(node);
            }
        }
        private void CreateBuildAttrbuteViewColumns()
        {
            this.dgvContent.AutoGenerateColumns = false;
            DataGridViewTextBoxColumn BTName = new DataGridViewTextBoxColumn();
            BTName.HeaderText = "建筑大类";
            BTName.DataPropertyName = "BTName";
            BTName.Name = "BTName";
            BTName.ReadOnly = true;
            DataGridViewTextBoxColumn SBTName = new DataGridViewTextBoxColumn();
            SBTName.HeaderText = "建筑子类";
            SBTName.Name = "SBTName";
            SBTName.ReadOnly = true;
            SBTName.DataPropertyName = "SBTName";
            DataGridViewTextBoxColumn SBAContent = new DataGridViewTextBoxColumn();
            SBAContent.HeaderText = "参数名称";
            SBAContent.ReadOnly = true;
            SBAContent.DataPropertyName = "SBAContent";
            SBAContent.Name = "SBAContent";
            DataGridViewTextBoxColumn SBADescribe = new DataGridViewTextBoxColumn();
            SBADescribe.HeaderText = "参数描述";
            SBADescribe.ReadOnly = true;
            SBADescribe.DataPropertyName = "SBADescribe";
            SBADescribe.Name = "SBADescribe";
            DataGridViewTextBoxColumn SAContent = new DataGridViewTextBoxColumn();
            SAContent.HeaderText = "参数值";
            SAContent.DataPropertyName = "SAContent";
            SAContent.Name = "SAContent";
            DataGridViewTextBoxColumn SADescribe = new DataGridViewTextBoxColumn();
            SADescribe.HeaderText = "参数值描述";
            SADescribe.DataPropertyName = "SADescribe";
            SADescribe.Name = "SADescribe";
            DataGridViewTextBoxColumn SAID = new DataGridViewTextBoxColumn();
            SAID.HeaderText = "参数值编号";
            SAID.DataPropertyName = "SAID";
            SAID.Name = "SAID";
            SAID.Visible = false;
            this.dgvContent.Columns.Add(BTName);
            this.dgvContent.Columns.Add(SBTName);
            this.dgvContent.Columns.Add(SBAContent);
            this.dgvContent.Columns.Add(SBADescribe);
            this.dgvContent.Columns.Add(SAContent);
            this.dgvContent.Columns.Add(SADescribe);
            this.dgvContent.Columns.Add(SAID);
            this.dgvContent.AllowUserToAddRows = false;
        }
        private void CreateDesignDcriterionViewColumns()
        {
            dgvContent.AutoGenerateColumns = false;
            DataGridViewTextBoxColumn DTName = new DataGridViewTextBoxColumn();
            DTName.HeaderText = "规范大类";
            DTName.DataPropertyName = "DTName";
            DTName.Name = "DTName";
            DTName.ReadOnly = true;
            DataGridViewTextBoxColumn DSTName = new DataGridViewTextBoxColumn();
            DSTName.HeaderText = "规范子类";
            DSTName.Name = "DSTName";
            DSTName.DataPropertyName = "DSTName";
            DSTName.ReadOnly = true;
            DataGridViewTextBoxColumn DSTDescribe = new DataGridViewTextBoxColumn();
            DSTDescribe.HeaderText = "规范子类描述";
            DSTDescribe.DataPropertyName = "DSTDescribe";
            DSTDescribe.Name = "DSTDescribe";
            DSTDescribe.ReadOnly = true;
            DataGridViewTextBoxColumn DCID = new DataGridViewTextBoxColumn();
            DCID.HeaderText = "规范内容编号";
            DCID.DataPropertyName = "DCID";
            DCID.Name = "DCID";
            DCID.Visible = false;
            DataGridViewTextBoxColumn DcriterionContent = new DataGridViewTextBoxColumn();
            DcriterionContent.HeaderText = "规范具体内容";
            DcriterionContent.DataPropertyName = "DcriterionContent";
            DcriterionContent.Name = "DcriterionContent";
            DataGridViewTextBoxColumn DcriterionRules = new DataGridViewTextBoxColumn();
            DcriterionRules.HeaderText = "所属政策规定";
            DcriterionRules.DataPropertyName = "DcriterionRules";
            DcriterionRules.Name = "DcriterionRules";
            dgvContent.Columns.Add(DTName);
            dgvContent.Columns.Add(DSTName);
            dgvContent.Columns.Add(DSTDescribe);
            dgvContent.Columns.Add(DcriterionContent);
            dgvContent.Columns.Add(DcriterionRules);
            dgvContent.Columns.Add(DCID);
            dgvContent.AllowUserToAddRows = false;
        }
        private DataSet GetBuildAttrbute(int sbaid)
        {
            dataSet = new DataSet();
            BLL.GetBuildAttributes BllGetBuildAttribute = new GetBuildAttributes();
            return dataSet = BllGetBuildAttribute.GetList("c.SBAID=" + "'" + sbaid + "'");
        }
        private void UpdateAttrtibute()
        {
            DialogResult dr = MessageBox.Show("是否确认修改所选定的内容？", "修改提示对话框", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dr == DialogResult.Yes)
            {
                bllSubAttribute = new BLL.T_SubAttributes();
                modelSubAttribute = new Model.T_SubAttributes();
                modelSubAttribute.SAID = Convert.ToInt32(dgvContent.CurrentRow.Cells["SAID"].Value.ToString());
                modelSubAttribute.SAContent = dgvContent.CurrentRow.Cells["SAContent"].Value.ToString();
                modelSubAttribute.SBAID = sbaid;
                modelSubAttribute.SADescribe = dgvContent.CurrentRow.Cells["SADescribe"].Value.ToString();
                try
                {
                    if (bllSubAttribute.Update(modelSubAttribute) == true)
                    {
                        MessageBox.Show("参数值更新成功！");
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                return;
            }

        }
        private void UpdateDesignDcriterion()
        {
            DialogResult dr = MessageBox.Show("是否确认修改所选定的内容？", "修改提示对话框", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dr == DialogResult.Yes)
            {
                bllBuildDesignDcriterionContent = new BLL.T_BuildDesignDcriterionContents();
                modelBuildDesignDcriterionContent = new Model.T_BuildDesignDcriterionContents();
                modelBuildDesignDcriterionContent.DCID = Convert.ToInt32(dgvContent.CurrentRow.Cells["DCID"].Value.ToString()); ;
                modelBuildDesignDcriterionContent.DSTID = dstid;
                modelBuildDesignDcriterionContent.DcriterionContent = dgvContent.CurrentRow.Cells["DcriterionContent"].Value.ToString();
                modelBuildDesignDcriterionContent.DcriterionRules = dgvContent.CurrentRow.Cells["DcriterionRules"].Value.ToString();
                try
                {
                    if (bllBuildDesignDcriterionContent.Update(modelBuildDesignDcriterionContent) == true)
                    {
                        MessageBox.Show("参数值更新成功！");
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                return;
            }

        }
        private void SelectChangeAttribute(int selectTag, string selectText)
        {
            foreach (TreeNode nd in trvBuildAttrbute.Nodes[0].Nodes)
            {
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    foreach (TreeNode treeNodeTwo in treeNode.Nodes)
                    {
                        if (treeNodeTwo.Text == selectText && Convert.ToInt32(treeNodeTwo.Tag) == selectTag)
                        {
                            dgvContent.Columns.Clear();
                            CreateBuildAttrbuteViewColumns();
                            dataSet = new DataSet();
                            dgvContent.DataSource = null;
                            sbaid = Convert.ToInt32(treeNodeTwo.Tag);
                            dataSet.Clear();
                            dataSet = GetBuildAttrbute(sbaid);
                            dgvContent.DataSource = dataSet.Tables[0];
                        }
                    }
                }

            }
        }
        private void SelectChangeDcriterion(int selectTag, string selectText)
        {
            foreach (TreeNode nd in trvDesignDcriterion.Nodes[0].Nodes)
            {
                foreach (TreeNode treeNode in nd.Nodes)
                {
                    if (treeNode.Text == selectText && Convert.ToInt32(treeNode.Tag) == selectTag)
                    {
                        dgvContent.Columns.Clear();
                        CreateDesignDcriterionViewColumns();
                        BLL.GetDesignDcriterions bllGetDesignDcriterion = new GetDesignDcriterions();
                        dataSet = new DataSet();
                        dstid = Convert.ToInt32(trvDesignDcriterion.SelectedNode.Tag);
                        dataSet.Clear();
                        dataSet = bllGetDesignDcriterion.GetList("b.DSTID=" + "'" + dstid + "'");
                        dgvContent.DataSource = null;
                        dgvContent.DataMember = null;
                        dgvContent.DataSource = dataSet;
                        dgvContent.DataMember = dataSet.Tables[0].ToString();
                    }
                }
            }
        }
        #endregion
    }
}
